class Solution {
    List<Integer> path;
    List<List<Integer>> ret;
    boolean[] check;
    public List<List<Integer>> permuteUnique(int[] nums) {
        path = new ArrayList<>();
        ret = new ArrayList<>();
        check = new boolean[nums.length];
        //先排序再递归
        Arrays.sort(nums);

        dfs(nums,0);
        return ret;
    }
    public void dfs(int[] nums,int pos) {
        //递归出口
        if(nums.length == path.size()) {
            ret.add(new ArrayList<>(path));
            return;
        }
        for(int i=0;i<nums.length;i++) {
            //剪枝
            if(check[i]==true||(i!=0 && nums[i]==nums[i-1] && check[i-1]==false)) {
                continue;
            }
            path.add(nums[i]);
            check[i] = true;
            dfs(nums,pos+1);//这里不能写成i+1
            //回溯——》恢复现场
            check[i] = false;
            path.remove(path.size()-1);
        }


    }
}p